package cn.openea.perpartner.componet.web.controller;

import cn.openea.perpartner.componet.web.entity.InsMsg;
import cn.openea.perpartner.componet.web.service.ISendMsgService;
import cn.openea.perpartner.componet.web.service.ITemplateMsgService;
import cn.openea.perpartner.componet.web.vo.MsgQueryVo;
import cn.openea.perpartner.componet.web.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Name: 消息管理
 *  计划包含 公众号消息发送，短信发送，查询等计API
 * @author: Mr.Yun
 * @Created: 2023/2/9 15:11
 */
@Api(tags = "消息管理")
@RestController
@RequestMapping("/msg")
public class MsgController {

    @Autowired
    ITemplateMsgService iTemplateMsgService;

    @Autowired
    ISendMsgService iSendMsgService;

    @ApiOperation("获取消息列表")
    @PostMapping("/list")
    public R selectListAllByPage(@RequestBody MsgQueryVo queryVo) {
        return iTemplateMsgService.selectListByPage(queryVo);
    }
    @ApiOperation("获取消息列表2")
    @PostMapping("/all/list")
    public R selectLocalAndBpmList(@RequestBody MsgQueryVo queryVo) {
        return iTemplateMsgService.selectLocalAndBpmList(queryVo);
    }

    @ApiOperation("写入消息到系统")
    @PostMapping("/savemsg")
    public R saveMsg(@RequestBody InsMsg msg) {
        return iTemplateMsgService.saveOrUpdate(msg)?R.ok():R.error();
    }

    @ApiOperation("发送模板消息")
    @PostMapping("/isendtemp")
    public R sendTemplateMsg(@RequestBody InsMsg msg) {
        return iSendMsgService.sendTemplateMsg(msg);
    }

    @ApiOperation("更新消息为已读")
    @PostMapping("/updateread")
    public R updateMsgReadById(@RequestParam Long msgid) {
        return iTemplateMsgService.updateMsgReadById(msgid);
    }

    @ApiOperation("更新消息为已读2")
    @PostMapping("/mark/read")
    public R updateLocalAndBpmMsgReadById(@RequestParam String msgid) {
        return iTemplateMsgService.updateLocalAndBpmMsgReadById(msgid);
    }
    @ApiOperation("更新消息为未读")
    @PostMapping("/mark/unread")
    public R updateLocalAndBpmMsgUnReadById(@RequestParam String msgid) {
        return iTemplateMsgService.updateLocalAndBpmMsgUnReadById(msgid);
    }


    @ApiOperation("标记消息为删除")
    @PostMapping("/deletemark")
    public R deleteMarkMsgById(@RequestParam Long msgid) {
        return iTemplateMsgService.deleteMarkMsgById(msgid);
    }
    @ApiOperation("标记消息为删除2")
    @PostMapping("/mark/delete")
    public R deleteMarkLocalAndBpmMsgById(@RequestParam String msgid) {
        return iTemplateMsgService.deleteMarkLocalAndBpmMsgById(msgid);
    }

    @ApiOperation("获取指定id的消息")
    @PostMapping("/getmsg")
    public R getMsgById(@RequestParam Long msgid) {
        return iTemplateMsgService.getMsgById(msgid);
    }

    @ApiOperation("发送文本消息")
    @PostMapping("/isendtext")
    public R sendTextMsg(@RequestParam String toWxOpenid, @RequestParam String msg) {
        return iSendMsgService.sendTextMsg(toWxOpenid, msg);
    }

}
